import configparser
import os.path

from settings import ROOT_PATH


class Config:
    configfile = os.path.join(ROOT_PATH, 'config.ini')

    def __init__(self):
        self.config = configparser.ConfigParser()
        self.config.read(self.configfile, encoding='utf-8')

    def get_log_config(self) -> dict:
        section = 'log'
        return {
            'log_cli': self.config.getboolean(section, 'log_cli'),
            'log_cli_level': self.config.get(section, 'log_cli_level', raw=True),
            'log_cli_date_format': self.config.get(section, 'log_cli_date_format', raw=True),
            'log_cli_format': self.config.get(section, 'log_cli_format', raw=True),
            'log_dir': self.config.get(section, 'log_dir', raw=True),
            'log_file_level': self.config.get(section, 'log_file_level', raw=True),
            'log_file_date_format': self.config.get(section, 'log_file_date_format', raw=True),
            'log_file_format': self.config.get(section, 'log_file_format', raw=True),
        }

    def get_mysql_config(self) -> dict:
        section = 'mysql'
        return {
            'host': self.config.get(section, 'host'),
            'port': self.config.getint(section, 'port'),
            'username': self.config.get(section, 'username'),
            'password': self.config.get(section, 'password'),
            'database': self.config.get(section, 'database'),
            'charset': self.config.get(section, 'charset'),
        }


if __name__ == '__main__':
    conf = Config()
    conf.get_log_config()
    conf.get_mysql_config()
